In this tutorial you will learn how to get started with version control using git and GitHub. The main goal here is to provide a step-by-step introduction to GitHub, with detailed screenshots, so that you become familiar with its main functionalities.
This tutorial is intended for grad students and academics who use R but are unfamiliar with the command line or terminal. I assume nothing about the computer science skills of the user.
The outline is provided in the floating table of contents.
Familiarity with GitHub has become an indispensible tool for anyone working with data. Sharing code, writing software for your statistical method, producing techincal reports and creating websites have become essential skills to have in the rapidly growing field of data science. Other answers can be found here, here and here.
Each of the topics covered are separated by chapters that should be followed sequentially. Within each chapter, there are a series of steps that you need to complete. Each step starts with some instructions followed by a screenshot.
Note: the screenshots provided here are from a Windows operating system, however it will be similar on a Mac or Linux.
Git is to GitHub, what R is to RStudio. In other words Git is the software that does all the work behind the scenes, and GitHub a user interface that makes its easier to communicate with Git (and adds functionality as well). Download Git
Once the download has completed, click on the Git-2.7.4 64-bit.exe file (.dmg on a Mac, or .deb on Linux). Note: the version you download might be different than what I’ve shown here, but that’s ok
Once you have read the GNU General Public License (this is not required to continue) click on Next.
You need to select where you want Git installed. I have chosen the default location Program Files, but you can change this if you like by clicking on the Browse... button. Once you have chosen a location click Next.
Select the components you want to install. Ensure that at least the boxes shown in the screenshot below have been checked. Click Next.
This step is to select where you want the shortcut location to be stored. I have chosen the default. Then click Next.
Git can be used from the command line also. Selecting the second option allows you this flexibility for when you become familiar with Git. Note: you might see different options on a Mac, if you don’t know which option to choose, select the default
Select the (recommended) first option and click Next. Note: you might see different options on a Mac, if you don’t know which option to choose, select the default
Select the (recommended) first option and click Next. Note: you might see different options on a Mac, if you don’t know which option to choose, select the default
Ensure that at least the Enable Git Credential Manager box is checked, and click Next.
You should see now see the following installation screen.
The following screen will appear once the Git setup has successfully completed. Click on Finish. Well done, you have installed Git on your system. Proceed to Chapter 2 to signup for a GitHub account.
hello world tutorialIn this short Chapter, you will signup for a GitHub account. GitHub is like your online portfolio of code. It has a plethora of great features for creating websites, project pages and collaborating with others. Again GitHub is an interface to the version control system called Git. Other options include Bitbucket and GitLab.
The longest step in this chapter is choosing your username. Think about it carefully; it will be how you are recognized on GitHub i.e., your github website address will be github.com/username. Once you have chosen a username, enter a valid email address and password, and click on the Sign up for GitHub button.
Choose the free plan (default) and click on the Finish sign up button.
Well done. You now have a GitHub account. Complete the Hello World guide which will walk you through some functionalities of GitHub. Click on the Let's get started! button.
Complete the exercises and move on to Chapter 3: Installing GitHub Desktop.
Traditionally, version control with Git is accessed through the command line or terminal. GitHub Desktop is a software program that makes it easier to use Git functions without having to use the command line. It also allows you to communicate with your GitHub website (github.com/username). Don’t worry if the differences between Git, GitHub and GitHub Desktop are not clear to you yet. You will have a better understanding once you have completed this tutorial. Note: in all the screenshots that follow, my username is shown, however you should be entering your username, password and email address created in Chapter 2.
Go to https://desktop.github.com/ and click on Download GitHub Desktop. Note: GitHub desktop is only available for Windows and Mac. If you are running Linux I recommend GitKraken.
Once the program has finished downloading, click on GitHubSetup.exe (or .dmg on a Mac).
Click on Install.
You should see this installation screen.
Once installed, open up the program and login using the GitHub username and password you created in Chapter 2 and click on Log in.
This information is used to identify the person that made the changes to your code. Leave the default values and click on Continue.
You should see this screen, since you haven’t created any local repositories yet.
What is a repository? The purpose of Git is to manage a project, or a set of files, as they change over time. Git stores this information in a data structure called a repository1.
You should now be at this screen.
Click on the plus button in the top left corner. Your username should appear with a list of your repositories that are currently saved in your online GitHub account. To be able to have a local copy of this repository (by local I mean on your computer hard drive) click on the Clone tab and then the Clone hello-world button (I am assuming that you completed the Hello World tutorial in Step 5 of Chapter 2).
Choose where you want to save a local copy of the Hello World repository and click OK.
You should now see the following contents in your GitHub desktop program.
Using your computer’s file explorer (e.g. windows explorer or mac finder), locate the local GitHub repository. If you successfully cloned your repository you will see a hello-world folder with a README.md file in it, which is the same one you created during the Hello World exercise in Chapter 2.
Before moving on to Chapter 4, verify that the GitHub Desktop has added an SSH key for you. An SSH key is used to establish a secure connection between your computer and the online GitHub server. On the far top right hand side of your online GitHub account click on the icon and navigate to Settings.
You should see one entry in the SSH keys panel. Well done. You are now ready to version control some R code in Chapter 4.
R code using an example of PCA